From 0e0f39af2e6585d7b61cf67652cdc0c2b2f06eb8 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 18 Jan 2023 19:44:27 -0800 Subject: pots --- src/routes/(app)/invoice/[hash]/+layout.server.js | 19 ++ src/routes/(app)/invoice/[hash]/+layout.svelte | 1 + src/routes/(app)/invoice/[hash]/+page.server.js | 5 + src/routes/(app)/invoice/[hash]/+page.svelte | 158 +++++++++++++ src/routes/(app)/invoice/[hash]/paid/+page.svelte | 62 +++++ .../(app)/invoice/[hash]/tip/+page.server.js | 11 + src/routes/(app)/invoice/[hash]/tip/+page.svelte | 252 +++++++++++++++++++++ 7 files changed, 508 insertions(+) create mode 100644 src/routes/(app)/invoice/[hash]/+layout.server.js create mode 100644 src/routes/(app)/invoice/[hash]/+layout.svelte create mode 100644 src/routes/(app)/invoice/[hash]/+page.server.js create mode 100644 src/routes/(app)/invoice/[hash]/+page.svelte create mode 100644 src/routes/(app)/invoice/[hash]/paid/+page.svelte create mode 100644 src/routes/(app)/invoice/[hash]/tip/+page.server.js create mode 100644 src/routes/(app)/invoice/[hash]/tip/+page.svelte (limited to 'src/routes/(app)/invoice/[hash]') diff --git a/src/routes/(app)/invoice/[hash]/+layout.server.js b/src/routes/(app)/invoice/[hash]/+layout.server.js new file mode 100644 index 00000000..61a479ab --- /dev/null +++ b/src/routes/(app)/invoice/[hash]/+layout.server.js @@ -0,0 +1,19 @@ +import Qr from 'qrcode-base64'; +import { get } from '$lib/utils'; +import { redirect } from '@sveltejs/kit'; + +export async function load({ depends, params, url }) { + depends('app:invoice'); + + let { hash } = params; + let invoice = await get(`/invoice?hash=${hash}`); + let { amount, received } = invoice; + amount = parseInt(amount); + + let paid = (!amount && received) || (amount > 0 && received >= amount); + if (paid && !url.pathname.endsWith('paid')) throw redirect(307, `/invoice/${hash}/paid`); + + let sm = Qr.drawImg(invoice.text, { size: 300 }); + + return { hash, invoice, sm, lg: sm }; +} diff --git a/src/routes/(app)/invoice/[hash]/+layout.svelte b/src/routes/(app)/invoice/[hash]/+layout.svelte new file mode 100644 index 00000000..4fa864ce --- /dev/null +++ b/src/routes/(app)/invoice/[hash]/+layout.svelte @@ -0,0 +1 @@ + diff --git a/src/routes/(app)/invoice/[hash]/+page.server.js b/src/routes/(app)/invoice/[hash]/+page.server.js new file mode 100644 index 00000000..1068f273 --- /dev/null +++ b/src/routes/(app)/invoice/[hash]/+page.server.js @@ -0,0 +1,5 @@ +import invoice from '$lib/invoice'; + +export const actions = { + default: invoice +}; diff --git a/src/routes/(app)/invoice/[hash]/+page.svelte b/src/routes/(app)/invoice/[hash]/+page.svelte new file mode 100644 index 00000000..28ff27c0 --- /dev/null +++ b/src/routes/(app)/invoice/[hash]/+page.svelte @@ -0,0 +1,158 @@ + + + + +
+
+ +
+ +
+ +
+ + {#if address} +
{address}
+ {/if} + +
+ + + {#if user && user.username !== username} + + + + {/if} +
+ +
+ {#if invoice.tip} +
+ {$t('invoice.invoice')} + + {f(amountFiat, currency)} + {`${sat(amount)}`} + +
+ +
+ {$t('invoice.tip')} + {f(tipAmount, currency)} + {`${sat(tip)}`} + +
+ {/if} + + {#if amount > 0} +
+ {$t('invoice.total')} + {f(amountFiat + parseFloat(tipAmount), currency)} + {`${sat(tip + amount)}`} +
+ {/if} +
+
+ + diff --git a/src/routes/(app)/invoice/[hash]/paid/+page.svelte b/src/routes/(app)/invoice/[hash]/paid/+page.svelte new file mode 100644 index 00000000..2ccbc971 --- /dev/null +++ b/src/routes/(app)/invoice/[hash]/paid/+page.svelte @@ -0,0 +1,62 @@ + + +
+
+ +
+ {#if received} +

{$t('invoice.paymentSuccessful')}

+

+ {f(amountFiat, currency)} + {#if tip} + + {f(tipFiat, currency)} + {/if} +

+

+ {sat(received - tip)} + {#if tip} + +{sat(tip)} + {/if} +

+ {/if} + + {#if pending} +

Payment detected

+

+ {f(pendingFiat, currency)} + {#if tip} + + {f(tipFiat, currency)} + {/if} +

+

+ {sat(pending - tip)} + {#if tip} + +{sat(tip)} + {/if} +

+ {/if} +
+ + +
+ + +
{$t('payments.tapAnywhere')}
diff --git a/src/routes/(app)/invoice/[hash]/tip/+page.server.js b/src/routes/(app)/invoice/[hash]/tip/+page.server.js new file mode 100644 index 00000000..c78e5020 --- /dev/null +++ b/src/routes/(app)/invoice/[hash]/tip/+page.server.js @@ -0,0 +1,11 @@ +import invoice from '$lib/invoice'; +import { redirect } from '@sveltejs/kit'; + +export async function load({ parent }) { + let { invoice } = await parent(); + if (!invoice.amount) throw redirect(307, `/invoice/${invoice.id}`); +} + +export const actions = { + default: invoice +}; diff --git a/src/routes/(app)/invoice/[hash]/tip/+page.svelte b/src/routes/(app)/invoice/[hash]/tip/+page.svelte new file mode 100644 index 00000000..308720ab --- /dev/null +++ b/src/routes/(app)/invoice/[hash]/tip/+page.svelte @@ -0,0 +1,252 @@ + + + + +
+
+ + + + + + + + +

{$t('invoice.addTipq')}

+ {#if !showCustomAmount} +
{Math.round(tipPercent)}%
+ + + +
+
+ + {f(amountFiat, currency)} + +{f(tipAmount, currency)} + +
+ +
+ {sat(amount)} + +{sat(tip)} +
+
+ + {#if tip} +
+ + +
+ {:else} + {#each tipAmounts as amount} + + {/each} + {/if} + +
+ +
+ {/if} + +
+
+ + {/if} +
+ + -- cgit v1.2.3